home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.12 Dec 90 / Simulation code / SimulationToolbox.d < prev    next >
Encoding:
Modula Definition  |  1989-06-18  |  3.4 KB  |  105 lines  |  [TEXT/MPS ]

  1. (****************************************************)
  2. (*                                                    *)
  3. (*    file:  SimulationToolbox.d                        *)
  4. (*                                                    *)
  5. (*  This module defines a set of subroutines for    *) 
  6. (*    doing discrete event simulation, using a         *)
  7. (*    "process" viewpoint.                            *)
  8. (*                                                    *)
  9. (*    Written in SemperSoft Modula-2 v.1.1.2            *)
  10. (*                                                    *)
  11. (*  Allen Stenger    May 1989                        *)
  12. (*                                                    *)
  13. (****************************************************)
  14.  
  15. DEFINITION MODULE SimulationToolbox;
  16.  
  17. FROM SYSTEM        IMPORT    ADDRESS;
  18.  
  19. TYPE
  20.     Duration    =     CARDINAL;    (* in units of time as
  21.                                 defined by the caller *)
  22.     Starter        =    PROCEDURE ( ADDRESS );
  23.     SimulationQueue;
  24.     Requester;
  25.     
  26. (*  CreateNewThread starts a new thread of execution in 
  27.     the simulation, beginning execution at routine 
  28.     starter, which is passed the address of a parameter 
  29.     block so that it knows what to do.  The worksize is
  30.     the size (in bytes) of the stack to be allocated for 
  31.     this thread.  The calling thread is suspended and 
  32.     the new thread beings execution.  (Note that the 
  33.     calling thread will be resumed to complete its 
  34.     execution for the current time before the time can 
  35.     be advanced.)  Initial execution of the program is 
  36.     also considered to be a thread. 
  37. *)
  38. PROCEDURE CreateNewThread(     starter : Starter; 
  39.                             parameterAddress : ADDRESS;
  40.                             worksize : CARDINAL );
  41.                         
  42. (*    Hold is called to simulate a delay (while work is 
  43.     being simulated).  The calling thread is suspended
  44.     until this much simulated time has passed.  The 
  45.     order of execution of threads becoming active at 
  46.     the same simulated time is not defined.  Hold(0) 
  47.     is legal.
  48. *)
  49. PROCEDURE Hold( howLong : Duration );
  50.  
  51. (*    HaltSimulation is called at the end of the 
  52.     simulation run and causes all threads to exit.
  53. *)
  54. PROCEDURE HaltSimulation;
  55.  
  56. (*    HaltThread is called by a thread to end its own 
  57.     existence.
  58. *)
  59. PROCEDURE HaltThread;
  60.  
  61. (*    CurrentTime returns the current simulated time (time
  62.     starts at 0).
  63. *)
  64. PROCEDURE CurrentTime() : Duration;
  65.  
  66. (****************************************************)
  67. (*    Queueing routines                                *)
  68. (****************************************************)
  69.  
  70. (*     InitializeQueue is called to create and initialize 
  71.     a queue.
  72. *)
  73. PROCEDURE InitializeQueue( VAR q : SimulationQueue );
  74.  
  75. (*    PlaceOrder is called to place the caller on a queue 
  76.     for service.  The parameterAddress is the address of 
  77.     a parameter block that will be interpreted by the 
  78.     server to determine the type of service needed.The 
  79.     caller is suspended until reactivated by the server, 
  80.     usually at the end of service.  More than one caller
  81.     may be queued; the order of service is FIFO.
  82. *)
  83. PROCEDURE PlaceOrder(     q : SimulationQueue; 
  84.                         parameterAddress : ADDRESS );
  85.  
  86. (*    Serve is called by a server to obtain the next order 
  87.     to serve.  The identity of the requester is returned 
  88.     so that the server may resume the requester when 
  89.     done.  If there are no orders, the caller is 
  90.     suspended until an order arrives.  More than one 
  91.     server may wait on the same queue; the order in 
  92.     which orders are given to servers is FIFO.
  93. *)
  94. PROCEDURE Serve( q: SimulationQueue; 
  95.                 VAR parameterAddress : ADDRESS; 
  96.                 VAR r : Requester );
  97.  
  98. (*    Reactivate is called by a server to resume execution 
  99.     of the requester.  The requester becomes ready to 
  100.     run at the current time.  The caller continues to 
  101.     run until it gives up control.
  102. *)
  103. PROCEDURE Reactivate( r : Requester );
  104.  
  105. END SimulationToolbox.